﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using seiacpscs_a2.datastructures.hashtable;
using seiacpscs_a2.datastructures.tree;

namespace seiacpscs_a2.datastructures
{
    public class DataStructureFactory
    {
        public const String BINARY_SEARCH_TREE = "bst_recursive";
        public const String HASH_TABLE = "hashtable";
        public const String STRAT_MODULO = "modulo";
        public const String STRAT_REFLEXIVE = "reflexive";
        public static DataStructure createHashTableWithModuloStrategy(int[] items)
        {

            HashTableStrategy strategy = new ModuloStrategy();
            return new HashTable(items, strategy);

        }

        public static DataStructure createHashTableWithReflexiveStrategy(int[] items)
        {

            HashTableStrategy strategy = new ReflexiveStrategy();
            return new HashTable(items, strategy);

        }

        public static DataStructure create(String dataStructure, String strategyName = null, int[] items = null)
        {
            DataStructure ds = null;

            if (items == null)
                items = new int[0];

            if( BINARY_SEARCH_TREE.Equals(dataStructure))
            {
                var bst_recur = new BinarySearchTreeRecursive();
                bst_recur.addItems(items);
                ds = bst_recur;
            }
            else if (HASH_TABLE.Equals(dataStructure))
            {
                if (STRAT_MODULO.Equals(strategyName) || strategyName == null)
                {
                    ds = createHashTableWithModuloStrategy(items);
                }
                else if (STRAT_REFLEXIVE.Equals(strategyName))
                {
                    ds = createHashTableWithReflexiveStrategy(items);
                }
            }
            else
            {
                throw new System.ArgumentException(string.Format("dataStructure name is not a valid parameter please use {0} or {1}", BINARY_SEARCH_TREE, HASH_TABLE)); 
            }
            return ds;
        }

    
    }
}
